<!-- +----------------------------------------------------------------------
| 麦沃德科技赋能开发者，助力中小企业发展 
+----------------------------------------------------------------------
| Copyright (c) 2017～2024  www.wdadmin.cn    All rights reserved.
+----------------------------------------------------------------------
| 沃德代驾系统并不是自由软件，不加密，并不代表开源，未经许可不可自由转售和商用
+----------------------------------------------------------------------
| Author: MY WORLD Team <bd@maiwd.cn>   www.wdadmin.cn
+----------------------------------------------------------------------
| 设置 开发者: 麦沃德科技-半夏  
+---------------------------------------------------------------------- -->

<template>
	<view class="container" :style="{'--theme-color': themeColor}">
		<!-- 菜单列表 -->
		<view class="container-list">
			<view class="list-item flex align-items-center" @click="toAgreement(2)">
				<view class="item-title flex-item">法律条款与平台规则</view>
				<image class="item-right" src="/static/right.png" mode="aspectFit"></image>
			</view>
			<view class="list-item flex align-items-center" @click="toAgreement(3)">
				<view class="item-title flex-item">用户协议</view>
				<image class="item-right" src="/static/right.png" mode="aspectFit"></image>
			</view>
			<view class="list-item flex align-items-center" @click="toAgreement(4)">
				<view class="item-title flex-item">隐私政策</view>
				<image class="item-right" src="/static/right.png" mode="aspectFit"></image>
			</view>
			<view class="list-item flex align-items-center">
				<view class="item-title flex-item">声音</view>
				<view class="item-switch" :class="{select: isOpenSound}" @click="changeSound()">
					<view class="switch-round"></view>
				</view>
			</view>
			<view class="list-item flex align-items-center">
				<view class="item-title flex-item">振动</view>
				<view class="item-switch" :class="{select: isOpenVibrate}" @click="changeVibrate()">
					<view class="switch-round"></view>
				</view>
			</view>
			<view class="list-item flex align-items-center" @click="toLogoff()">
				<view class="item-title flex-item">注销账号</view>
				<image class="item-right" src="/static/right.png" mode="aspectFit"></image>
			</view>
			<view class="list-item flex align-items-center">
				<view class="item-title flex-item">版本号</view>
				<text class="item-tag">{{version}}</text>
			</view>
		</view>
		<!-- 退出登录 -->
		<view class="container-btn" v-if="token" @click="handleExit">退出登录</view>
	</view>
</template>

<script>
	import { mapState } from "vuex"
	export default {
		data() {
			return {
				// 页面是否阻止滚动
				pageShow: false,
				// 加载完成
				loadEnd: false,
				// 登录鉴权
				token: "",
				// 声音打开状态
				isOpenSound: true,
				// 振动打开状态
				isOpenVibrate: true,
			}
		},
		computed: {
			...mapState({
				themeColor: state => state.app.themeColor,
				version: state => state.app.version,
			})
		},
		onShow() {
			this.token = uni.getStorageSync("token")
			const soundAndVibrate = uni.getStorageSync("soundAndVibrate")
			if (soundAndVibrate) {
				this.isOpenSound = soundAndVibrate.soundOpen
				this.isOpenVibrate = soundAndVibrate.vibrateOpen
			} else {
				this.isOpenSound = true
				this.isOpenVibrate = true
			}
		},
		methods: {
			// 改变页面滚动状态
			pageChange(state) {
				this.pageShow = state
			},
			// 跳转协议
			toAgreement(type) {
				this.$util.toPage({
					mode: 1,
					path: "/pages/driver/mine/settings/agreement?type=" + type
				})
			},
			// 改变声音打开状态
			changeSound() {
				this.isOpenSound = !this.isOpenSound
				const data = {
					soundOpen: this.isOpenSound,
					vibrateOpen: this.isOpenVibrate,
				}
				uni.setStorageSync("soundAndVibrate", data)
			},
			// 改变振动打开状态
			changeVibrate() {
				this.isOpenVibrate = !this.isOpenVibrate
				const data = {
					soundOpen: this.isOpenSound,
					vibrateOpen: this.isOpenVibrate,
				}
				uni.setStorageSync("soundAndVibrate", data)
			},
			// 跳转注销账号
			toLogoff() {
				this.$util.toPage({
					mode: 1,
					path: "/pages/driver/mine/settings/logoff",
					isToken: true,
				})
			},
			// 退出登录
			handleExit() {
				uni.showModal({
					title: "系统提示",
					content: "确定要退出登录吗？",
					confirmColor: "#DE2828",
					success: (res) => {
						if (res.confirm) {
							try {
								this.$util.request("login.logout", { token: uni.getStorageSync("token") })
								this.$store.commit('user/clearAuth')
								this.$util.toPage({
									mode: 1,
									path: "/pages/driver/mine/index"
								})
							} catch (error) {
								this.$store.commit('user/clearAuth')
								this.$util.toPage({
									mode: 1,
									path: "/pages/driver/mine/index"
								})
							}
						}
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	.container {
		padding: 32rpx;

		.container-list {
			background: #fff;
			border-radius: 32rpx;
			padding: 0 32rpx;

			.list-item {
				padding: 32rpx 0;
				border-bottom: 1px solid #EBEBEB;

				&:last-child {
					border-bottom: none;
				}

				.item-title {
					color: #242629;
					font-size: 28rpx;
					font-weight: 600;
					line-height: 40rpx;
				}

				.item-right {
					width: 24rpx;
					height: 24rpx;
					margin-left: 32rpx;
				}

				.item-tag {
					color: #242629;
					font-size: 28rpx;
					font-weight: 600;
					line-height: 40rpx;
					margin-left: 32rpx;
				}

				.item-switch {
					width: 80rpx;
					height: 40rpx;
					padding: 4rpx;
					background: #DEDEDE;
					border-radius: 24rpx;
					transition: all .3s;

					.switch-round {
						width: 32rpx;
						height: 32rpx;
						border-radius: 50%;
						background: #fff;
						margin-left: 0;
						transition: all .3s;
					}

					&.select {
						background: var(--theme-color);

						.switch-round {
							margin-left: calc(100% - 32rpx);
						}
					}
				}
			}
		}

		.container-btn {
			margin-top: 32rpx;
			padding: 36rpx;
			background: #fff;
			border-radius: 32rpx;
			text-align: center;
			color: var(--theme-color);
			font-size: 28rpx;
			font-weight: 600;
			line-height: 40rpx;
		}
	}
</style>